/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author israel
 */
@Entity
public class Functionality extends AbstractEntity{
    
    @Column(nullable = false, length = 45)
    private String name;
    
    @ManyToOne
    @JoinColumn(name="father_id")
    private Functionality father;
    
    @Column(name="call_page")
    private String callPage;
    
    private String template;
    
    public Functionality() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = "" + this.getName() + this.getCallPage()
                    + this.getTemplate()
                    + ((this.getFather() != null) ? this.getFather().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public Functionality(String name, Functionality father, String callPage, String template) {
        this.name = name;
        this.father = father;
        this.callPage = callPage;
        this.template = template;
    }

    public String getCallPage() {
        return callPage;
    }

    public void setCallPage(String callPage) {
        this.callPage = callPage;
    }

    public Functionality getFather() {
        return father;
    }

    public void setFather(Functionality father) {
        this.father = father;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTemplate() {
        return template;
    }

    public void setTemplate(String template) {
        this.template = template;
    }
}
